﻿
jQuery(document).ready(function () {
  
    $('#frAddNexOfKin').submit(function () {
        $('#msg-frAddNexOfKin').html("");
        App.blockUI($('#frAddNexOfKin'), false);
        $.ajax({
            type: "POST",
            url: "/NextOfKin/AddNextOfKin",
            data: $(this).serialize(),
            success: function (data) {
                if (data!=0) {
                    $('#msg-frAddNexOfKin').html("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Success!</strong> Nex of kin infomation has been added</div>");
                    $.ajax({
                        type: "POST",
                        url: "/NextOfKin/NextOfKinDetail",
                        data: {id:data},
                        success: function (res) {
                            $('#ListNexOfKinDetail').prepend(res);
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                        }
                    });
                    document.forms["frAddNexOfKin"].reset();
                    App.unblockUI($('#frAddNexOfKin'));
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#msg-frAddNexOfKin').html("Load failed");
                App.unblockUI($('#frAddNexOfKin'));
            }
        });
        return false;
    });
});
function deleteNextOfKin(id) {
    $('#msg-frNexOfKinDetail').html("");
    if (confirm('Are you sure?') == false) return false;
    var div = $('#NexOfKinDetail' + id);
    App.blockUI(div, false);
    $.ajax({
        type: "POST",
        url: "/NextOfKin/DeleteNextOfKin",
        data: {id:id},
        success: function (data) {
            $('#msg-frNexOfKinDetail').html(data);
            div.remove();
        },
        error: function (xhr, ajaxOptions, thrownError) {
            $('#msg-frNexOfKinDetail').html("Load failed");
            App.unblockUI(div);
        }
    });
    return false;
}